import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect:'/first',
    children:[
      {path: '/escort/escorthome', component: () => import('../views/escort/EscortHomeView.vue')},
      {path: '/notice', component: () => import('../views/notice/NoticeView.vue')},
      {path: '/userAgreement', component: () => import('../views/system/UserAgreementView.vue')},
      {path: '/privacyPolicy', component: () => import('../views/system/PrivacyPolicyView.vue')},
      {path: '/serviceType', component: () => import('../views/system/ServiceTypeView.vue')},
      {path: '/about', component: () => import('../views/system/AboutView.vue')},
      {path: '/contact', component: () => import('../views/system/ContactView.vue')},
      {path: '/serviceProcess', component: () => import('../views/system/ServiceProcessView.vue')},


    ]
  },

  {path: '/first', component: () => import('../views/FirstView.vue')},
  {path: '/login', component: () => import('../views/LoginView.vue')},
  {path: '/register', component: () => import('../views/RegisterView.vue')},

  {
    path: '/managerhome',
    component: () => import('../views/manager/ManagerHomeView.vue'),
    children: [
      { path: '/managerPersonal', component: () => import('../views/manager/ManagerPersonal.vue') },
      { path: '/escortAudit', component: () => import('../views/manager/EscortAuditView.vue') },
      { path: '/noticeManager', component: () => import('../views/manager/NoticeManagerView.vue') },
      { path: '/review', component: () => import('../views/manager/ReviewView.vue') },
      { path: '/serviceTrack', component: () => import('../views/manager/ServiceTrackView.vue') },
      { path: '/user', component: () => import('../views/manager/UserView.vue') },
      { path: '/escort', component: () => import('../views/manager/EscortView.vue') },
      { path: '/service', component: () => import('../views/manager/ServiceView.vue') },
      { path: '/appointment', component: () => import('../views/manager/AppointmentView.vue') }


    ]
  },


{
  path: '/escorthome',
      component: () => import('../views/escort/EscortHomeView.vue'),
  redirect: '/escortfirst', // 默认跳转到 escortfirst 页面
    children: [
        { path: '/appointments', component: () => import('../views/escort/AppointmentsView.vue') },
  // { path: '/appointmentdetail/：id', component: () => import('../views/escort/AppointmentDetail.vue') },
  { path: '/escortfirst', component: () => import('../views/escort/EscortFirstView.vue') },
  { path: '/escort-reviews', component: () => import('../views/escort/EscortReviewView.vue') },
  { path: '/service-track', component: () => import('../views/escort/EscortTrackView.vue') },
  { path: '/escortfooter', component: () => import('../views/escort/EscortFooter.vue') },
  { path: '/escortnotice', component: () => import('../views/escort/EscortNotice.vue') },


]
},

  {
    path: '/userhome',
    component: () => import('../views/user/UserHomeView.vue'),
    children:
        [
            {path:'/user/first',component:() =>import('../views/user/UserFirstView.vue')},
            {path:'/user/info',component:() =>import('../views/user/UserInfo.vue')},
            {path: '/user/appointments', component: () => import('../views/user/UserAppointmentsView.vue')},
            {path: '/user/reviews', component: () => import('../views/user/UserReviewView.vue')},
            {path: '/user/favorites', component: () => import('../views/user/UserFavoritesView.vue')},
            {path: '/user/profile', component: () => import('../views/user/UserProfileView.vue')},
    ]
  },

  // {path:'/userFirst',component:() =>import('../views/user/UserView.vue')},

]


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  const isAuthenticated = !!localStorage.getItem('userId')

  if (to.meta.requiresAuth && !isAuthenticated) {
    next('/login')
  } else {
    next()
  }
})


export default router